package com.hq.controller;

import com.hq.bean.User;
import com.hq.service.StuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Resource
    private StuService stuService;
    @RequestMapping("reg.do")
    public String reg(User user){
        int i=stuService.saveReg(user);
        return "redirect:index.jsp";
    }

    @RequestMapping("login.do")
    public String login(User user, HttpSession session){
        // 登录
        User u=stuService.login(user);
        if(u!=null){
            session.setAttribute("user",user);
            return "redirect:list.do";
        }else{
            return "redirect:index.jsp";
        }
    }

    @RequestMapping("logout.do")
    public String logout(HttpSession session){
        session.invalidate();// session 注销
        return  "redirect:index.jsp";
    }
}
